<php> $count = count($list); </php>
<div class="C"></div>
<div class="pt10">
  <table width="95%">
    <tr>
      <td align="center" valign="top" class="fB" width="15%">{:L('comment')}</td>
      <td align="left"><textarea id="comment" class="in_put cl03" style="width:630px; height:100px"></textarea></td>
    </tr> <tr height="50">
      <td align="right"></td>
      <td align="left"><input id="comment_toId" type="hidden" value="0">
        <input type="button"  id="button_comment_add" value="{:L('comment_add')}" class="btn_sea" onClick="doAddComment()"/></td>
    </tr>
  </table>
  <div class="C"></div>
</div>
<div class="comment_list">
  <ul id="comment_list">
    <volist name="list" id="vo">
      <li id="comment_list{$vo.id}">
        <div class="headpic50 L" id="comment-{$vo['id']}"> <a href="{:U('space/view/index','uid='.$vo['uid'])}"><img width="50" src="{$vo.uid|getUserFace}"/></a> </div>
        <div class="list_cont">
          <div class="f12 cl06"> <span class="R">
            <php>echo $count-$key;</php>{:L('comment_floor')}</span> <a class="pr5"  class="preview" rel="{$vo.uid}" href="{:U('space/view/index','uid='.$vo['uid'])}" id="name{$vo.id}">{$vo.uid|getUserName}</a>{:L('comment_time')}<span class="cTime">{$vo.cTime|friendlyDate}</span> </div>
          <php> if($vo['toId'] != 0){ </php>
          <div class="restore_box">
            <div class="f12 cl06"> <span class="fB pr5 cl02">{:L('comment_restore')}</span> <a class="pr5" class="preview" rel="{$vo.child.uid}" href="{:U('space/view/index','uid='.$vo['child']['uid'])}">{$vo.child.uid|getUserName}</a> {:L('comment_time')} {$vo.child.cTime|friendlyDate} </div>
            <div class="C_cont"> {$vo.child.comment|nl2br} </div>
          </div>
          <php> } </php>
          <div class="C_cont w690"><span id="comment_data{$vo.id}"> {$vo.comment|nl2br} </span> <a class="f12 ml10" href="javascript:void(0)" onClick="replay({$vo.id})">{:L('comment_restore')}</a>
            <php>if($areAdmin){</php>
            <a class="f12 ml5" href="javascript:void(0)" onClick="deleteCommentDate({$vo.id})">{:L('common_delete')}</a>
            <php>}</php>
          </div>
        </div>
        <div class="C"> </div>
      </li>
    </volist>
  </ul>
</div>
<php>$count++;</php>
<div id="comment_tpl_data" style="display:none;">
  <div class="headpic50 L"> <a href="{:U('space/view/index','uid='.$mid)}"><img width="50" src="{$mid|getUserFace}"/></a> </div>
  <div class="list_cont">
    <div class="replay_a f12 cl06"> <span class="R">{$count}<?php echo L('comment_floor'); ?></span> <a class="pr5"  class="preview" rel="{$vo.uid}" href="" id="">{$mid|getUserName}</a> {:L('comment_time')} {:L('common_now')}</div>
    <div class="C_cont"> </div>
  </div>
  <div class="C"> </div>
</div>
<div id="comment_tpl_replay" style="display:none;">
  <div class="restore_box">
    <div class="replay_a f12 cl06"> <span class="fB pr5 cl02">{:L('comment_restore')}</span> <a class="pr5" class="preview" rel="" href="{:U('space/view/index')}"></a>{:L('common_submit')}<span class="cTime"></span></div>
    <div class="C_cont"></div>
    <div class="C"></div>
  </div>
</div>
<script>

var comment_tpl = "";
var comment_tpl_replay=""
var comment_toUid = 0;
var comment_cTime = "";
var comment_comment = "";
var comment_toName ="";
var count = {$count};
var comment_model = '{$model}';
var comment_field = '{$field}';
var comment_idField = '{$idField}';
var url = '{$url}';
var title= '{$title}';
var mid  = '{$admin}';
var appName = '{$appName}';


function replay( id ){
  var obj = $( '#comment' );
  if( id != "false" ){
    var old_con = obj.val();
    //通过:号分割，不能同时回复几个人
    array = old_con.split(":");
    new_con = "{:L('comment_restore')}"+$( '#name'+id ).html() ;
    if( array[0] != new_con ){
      if( array[1] ){
        obj.val( new_con+":"+array[1] );
      }else{
        obj.val( new_con+":");
      }
    }
				$('#comment_toId').val(id);
				comment_toName=$( '#name'+id ).html();
				comment_toUid = $( '#name'+id ).attr('rel');
				comment_cTime = $( '#name'+id+' ~ '+'.cTime' ).text();
				comment_comment = $('#comment_data'+id).html();
  }else{
    obj.focus();
				
  }
		 achorToOrder(false);
}

function doAddComment(){
	var _this = $('#button_comment_add');
	
	_this.attr('disabled','disabled');
	var old_button = _this.val();
	_this.val('{:L('comment_waiting')}');
	
	
	var temp_tpl_comment = comment_tpl.clone();
	var comment = $.trim($('#comment').val());
	array = comment.split(":");
	var toId    = $('#comment_toId').val();
	
	if(array.length <2 && toId !=0){
			toId = 0;
	}
	
	if(array.length >=2 && toId != 0){
		array.shift()
		comment = array.join(':');
	}

	if(comment.length < 2 ){
																						$.tbox.no('{:L('comment_error')}');
																			setTimeout('$.tbox.close()',1500);
																			$('#comment').val("");
																			$('#comment_toId').val("");
																			_this.removeAttr('disabled');
																			_this.val(old_button);
																			return;
	}


	var face    = '{$mid|getUserFace}';
	var appId   = '{$fid}';
	var type    = '{$type}';
	var name    = '{$mid|getUserName}';
	var level = count;
	var isGroup = '{$isGroup}';
	
	$.post(SITE_URL+'/index.php?app=home&mod=Comment&act=addComment',{isGroup:isGroup,toUid:comment_toUid,comment:comment,toId:toId,fid:appId,type:type,mode:comment_model,field:comment_field,idField:comment_idField,mid:mid,url:url,title:title,appName:appName},function(result){
																	if(result != 0){
																				comment_tpl.children('.list_cont').children('.replay_a').children('a').attr('id','name'+appId);
																			
																				comment_tpl.children('.list_cont').children('.C_cont').html(result);
																				comment_tpl.children('.list_cont').children('.replay_a').children('span').html(level+'{:L('comment_floor')}');
																				if(toId != 0){
																					var toId_tpl = comment_tpl_replay.children('.restore_box').children('.replay_a');
																					var href= SITE_URL+'/space/'+comment_toUid;
																						toId_tpl.children('a').attr('rel',comment_toUid).attr('href',href).html(comment_toName);
																						toId_tpl.children('.cTime').html(comment_cTime);
																						comment_tpl_replay.children('.restore_box').children('.C_cont').html(comment_comment);
																						comment_tpl.children('.list_cont').children('.replay_a').after(comment_tpl_replay.html());
																				}
																				count ++;
																				$('#comment_list').prepend('<li>'+comment_tpl.html()+'</li>');
																				
																			$('#comment').val("");
																			$('#comment_toId').val("");
																			_this.removeAttr('disabled');
																			_this.val(old_button);
																				comment_tpl = temp_tpl_comment;
																	}	else{
																			$.tbox.no('{:L('comment_error')}');
																			setTimeout('$.tbox.close()',1500);
																	}
	})


}

function deleteCommentDate(id){
	var appId = '{$fid}';
		$.post(SITE_URL+'/index.php?app=home&mod=Comment&act=deleteComment',{id:id,mode:comment_model,fid:appId,field:comment_field,idField:comment_idField},function(result){
																																																																																							if(result != 0){
																																																																																									$('#comment_list'+id).remove();																																																																																																																																		
																																																																																							}else{
																																																																																										$.tbox.no('{:L('comment_delete_error')}');
																																																																																										setTimeout('$.tbox.close()',1500);
																																																																																							}
																																																																																							});
}

$(function(){
											comment_tpl = $('#comment_tpl_data').clone();
											comment_tpl_replay = $('#comment_tpl_replay').clone();
											$('#comment_tpl_replay').remove();
											$('#comment_tpl_data').remove();
											var shortcutOpt = {'target':'comment'};
											shortcut('ctrl+return',	function(){doAddComment();},shortcutOpt);
											
											})
</script>
